import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;
import 'package:www.znpigai.teacher/global_store/state.dart';
import 'package:www.znpigai.teacher/utils/util.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    HomeworkState state, Dispatch dispatch, ViewService viewService) {
  String submitCount() {
    switch (state.status) {
      case "notStart":
        return "班级已提交${state.submittedCount}";
        break;
      case "underway":
        return "班级已提交${state.submittedCount}";
        break;
      case "finish":
        return "班级未提交${state.submittedCount}";
        break;
      case "reject":
        return "班级已提交${state.submittedCount}";
        break;
      case "remark":
        return "班级未提交${state.submittedCount}";
        break;
      case "notSubmit":
        return "班级已提交${state.submittedCount}";
        break;
      default:
        return "班级已提交${state.submittedCount}";
    }
  }

  MaterialColor statusColor() {
    switch (state.status) {
      case "notStart":
        return Colors.orange;
        break;
      case "underway":
        return Colors.orange;
        break;
      case "finish":
        return Colors.green;
        break;
      case "reject":
        return Colors.red;
        break;
      case "remark":
        return Colors.teal;
        break;
      case "notSubmit":
        return Colors.orange;
        break;
      default:
        return Colors.red;
    }
  }

  var isFinished = state.notremarkcount == 0 && state.notsubmit == 0;

  return Card(
    color: Colors.white,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(2.0),
    ),
    elevation: 2.0,
    margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
    child: GestureDetector(
        onTap: () => dispatch(HomeworkActionCreator.onClick()),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Row(children: <Widget>[
              SizedBox(width: 10),
              Text(
                state.title ?? '题目自拟',
                style: TextStyle(color: Colors.black, fontSize: 18.0),
              ),
              Spacer(),
              Image.asset(
                isFinished
                    ? 'assets/images/homework_yipigai_flag.png'
                    : 'assets/images/homework_daipigai_flag.png',
                width: 34,
              ),
              SizedBox(width: 10),
            ]),
            SizedBox(height: 10),
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 10),
              child: Text(
                Util.plainText(state.demand, defaultText: '无要求', maxLength: 50),
                maxLines: 2,
                style: TextStyle(fontSize: 15.0),
              ),
            ),
            Padding(
                padding: EdgeInsets.all(10.0),
                child: Wrap(
                  spacing: 8.0,
                  runSpacing: 4.0,
                  children: <Widget>[
                    Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 10, vertical: 2),
                      decoration: new BoxDecoration(
                        color: Colors.black12,
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        state.classEntityName,
                        style: TextStyle(color: Colors.black87, fontSize: 12),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 10, vertical: 2),
                      decoration: new BoxDecoration(
                        color: Colors.black12,
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        GlobalState.types[state.articleType],
                        style: TextStyle(color: Colors.black87, fontSize: 12),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 10, vertical: 2),
                      decoration: new BoxDecoration(
                        color: Color(0xFFD8E8FF),
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        isFinished ? '已结束' : '进行中',
                        style:
                            TextStyle(color: Colors.blueAccent, fontSize: 12),
                      ),
                    ),
                    Container(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 10, vertical: 2),
                      decoration: new BoxDecoration(
                        color: Color(0xFFFFE9BD),
                        shape: BoxShape.rectangle,
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                      child: Text(
                        "未提交 ${state.notsubmit}",
                        style: TextStyle(
                            color: Colors.deepOrangeAccent, fontSize: 12),
                      ),
                    ),
                  ],
                )),
            Divider(height: 1, indent: 10),
            Padding(
                padding: EdgeInsets.all(10.0),
                child: Row(
                  children: <Widget>[
                    Text(
                      '提交时间：',
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    ),
                    Text(
                      state.etime,
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    ),
                    SizedBox(width: 10),
                    Text(
                      state.ctime,
                      style: TextStyle(color: Colors.grey, fontSize: 12),
                    ),
                  ],
                )),
          ],
        )),
  );
}
